package com.ricky.handler.action;

import java.util.HashMap;
import java.util.Map;

import com.ricky.core.net.abs.Request;
import com.ricky.core.net.msg.Context;
import com.ricky.core.net.utils.Attributes;
import com.ricky.db.model.HeroData;
import com.ricky.game.GameWorld;
import com.ricky.game.Hero;
import com.ricky.game.scene.SceneBase;
import com.ricky.game.scene.SceneController;
import com.ricky.handler.IHandler;

/**
 * 进入场景
 * 
 * @author rik
 * 
 */
public class Scene implements IHandler {

	@SuppressWarnings("rawtypes")
	@Override
	public void proccess(Request request,Map<String,Object> context) {

		Map msg =context;
		int type = (Integer) msg.get("type");
		switch (type) {
		case 0: // 请求进入场景
			int scneID = (Integer) msg.get("sceneID");
			Hero h = (Hero) request.getAttribute(Attributes.HERO);
			if(scneID==0)
				scneID=1;
			int x=0,y=0,z=0;
			if(msg.containsKey("x") && msg.containsKey("y"))
			{
				x=(Integer) msg.get("x");
				y=(Integer) msg.get("y");
			}
			GameWorld.getInstance().transport(h, scneID,x,y,z);
			break;
		case 1: // 已经加载完成
			Hero h1 = (Hero) request.getAttribute(Attributes.HERO);
			SceneController sc=GameWorld.getInstance().getScene(h1.getSceneID());
			sc.enter(h1);
			break;
		case 10://广播
			Hero h2 = (Hero) request.getAttribute(Attributes.HERO);
			SceneBase sc1=h2.getCurrentScene();
			if(sc1!=null)
			{
				@SuppressWarnings("unchecked")
				Map<String,Object> data1=(HashMap<String,Object>)msg.get("arg");
				sc1.broadcast(h2,data1);
			}
			
			break;
		case 5://同步位置
			Hero h3 = (Hero) request.getAttribute(Attributes.HERO);
			SceneBase sc2=h3.getCurrentScene();
			Map pos=(Map) msg.get("pos");
			h3.setPostion((Integer) pos.get("x"),(Integer) pos.get("y"),(Integer) pos.get("z"));
			h3.getGraphic().setRotateY((Float) pos.get("rotateY"));
			sc2.synchrostep(h3);
			break;
		}
	}

}
